package com.sas.common.converter;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = false)
public class RoomTypeConverter implements AttributeConverter<Integer, String> {

    @Override
    public String convertToDatabaseColumn(Integer attribute) {
        if (attribute == null) return null;
        switch (attribute) {
            case 1: return "SINGLE";
            case 2: return "DOUBLE";
            case 3: return "TRIPLE"; // 数据库使用 TRIPLE
            case 4: return "SUITE";  // 数据库使用 SUITE
            default: return "SINGLE";
        }
    }

    @Override
    public Integer convertToEntityAttribute(String dbData) {
        if (dbData == null) return null;
        switch (dbData) {
            case "SINGLE": return 1;
            case "DOUBLE": return 2;
            case "TRIPLE": return 3;
            case "SUITE": return 4;
            // 兼容前端常用别名
            case "MULTIPLE": return 3;
            case "VIP": return 4;
            default: return 1;
        }
    }
}